from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtChart import *
from qtpy import QtCore


class Form1(QWidget):
    # def __init__(self, parent=None):
    #     super().__init__()
    #
    #     self.resize(1598, 842)
    #
    #     # 定义全局变量
    #     self.m_isPress = False  # 是否按下鼠标
    #     self.m_lastPoint = 0
    #     self.m_alreadySaveRange = False
    #     self.m_ctrlPress = False
    #     self.m_alreadySaveRange = True
    #
    #     # 坐标轴范围
    #     self.m_xMin = 0.00
    #     self.m_xmax = 5.00
    #     self.m_yMin = 0.00
    #     self.m_yMax = 6.00
    #
    #     # 添加数据
    #     self.series_1 = QLineSeries()  # 定义LineSerise，将类QLineSeries实例化
    #
    #     self._1_point_0 = QPointF(0.00, 0.00)  # 定义折线坐标点
    #     self._1_point_1 = QPointF(0.80, 6.00)
    #     self._1_point_2 = QPointF(2.00, 2.00)
    #     self._1_point_3 = QPointF(4.00, 3.00)
    #     self._1_point_4 = QPointF(1.00, 3.00)
    #     self._1_point_5 = QPointF(5.00, 3.00)
    #
    #     self._1_point_list = [self._1_point_0, self._1_point_1, self._1_point_4, self._1_point_2, self._1_point_3,
    #                           self._1_point_5]  # 定义折线点清单
    #     self.series_1.append(self._1_point_list)  # 折线添加坐标点清单
    #     self.series_1.setName("折线一")  # 折线命名
    #
    #     # 绘图设置
    #     self.x_Aix = QValueAxis()  # 定义x轴，实例化
    #     self.x_Aix.setRange(self.m_xMin, self.m_xmax)  # 设置量程
    #     self.x_Aix.setLabelFormat("%0.2f")  # 设置坐标轴坐标显示方式，精确到小数点后两位
    #     self.x_Aix.setTickCount(6)  # 设置x轴有几个量程
    #     self.x_Aix.setMinorTickCount(0)  # 设置每个单元格有几个小的分级
    #
    #     self.y_Aix = QValueAxis()  # 定义y轴
    #     self.y_Aix.setRange(self.m_yMin, self.m_yMin)
    #     self.y_Aix.setLabelFormat("%0.2f")
    #     self.y_Aix.setTickCount(7)
    #     self.y_Aix.setMinorTickCount(0)
    #
    #     self.charView = QChartView(self)  # 定义charView，父窗体类型为 Window
    #     self.charView.setGeometry(0, 0, self.width(), self.height())  # 设置charView位置、大小
    #     # self.charView.setGeometry(0, 0, 1500, 830)  # 设置charView位置、大小
    #     self.charView.chart().addSeries(self.series_1)  # 添加折线
    #     self.charView.chart().setAxisX(self.x_Aix)  # 设置x轴属性
    #     self.charView.chart().setAxisY(self.y_Aix)  # 设置y轴属性
    #     # self.x_Aix.hide()  # 隐藏x轴
    #     # self.y_Aix.hide()  # 隐藏y轴
    #     self.x_Aix.setMinorGridLineVisible(False)  # 隐藏次网格线
    #     self.y_Aix.setMinorGridLineVisible(False)  # 隐藏次网格线
    #     self.charView.chart().setTitleBrush(QBrush(Qt.cyan))  # 设置标题笔刷
    #     # self.charView.chart().setTitle("双折线")  # 设置标题
    #     self.charView.chart().legend().hide()  # 关闭图例
    #     # self.charView.show()  # 显示charView
    #     # self.charView.chart().scroll(1, 0)
    #
    #     # 页面布局设计
    #     self.main_layout = QHBoxLayout()  # 添加水平布局
    #     self.main_layout.addWidget(self.charView)
    #     self.setLayout(self.main_layout)


    def __init__(self):
        super().__init__()
        self.setWindowTitle('百度地图')
        self.setGeometry(5, 30, 1355, 730)
        self.move(50, 50)
        self.browser = QWebEngineView()
        self.browser.load(QUrl('http://lbsyun.baidu.com/jsdemo.htm#webgl6_1'))
        tabel_layout = QGridLayout()  # add gridlayout
        tabel_layout.addWidget(self.browser)
        self.setLayout(tabel_layout)


    def mouseMoveEvent(self, QMouseEvent):
        if QMouseEvent.button() == QtCore.Qt.LeftButton:
            self.m_lastPoint = QMouseEvent.pos()
            self.m_isPress = True

    def mouseReleaseEvent(self, QMouseEvent):
        self.m_isPress = False
        if QMouseEvent.button() == QtCore.Qt.RightButton:
            if self.m_alreadySaveRange:
                self.x_Aix.setRange(self.m_xMin, self.m_xmax)  # 设置量程
                self.y_Aix.setRange(self.m_yMin, self.m_yMin)

    def saveAxisRange(self):
        return 0

    def mouseMoveEvent(self, QMouseEvent):
        curPos = QMouseEvent.pos()
        if self.m_isPress:
            offset = curPos - self.m_lastPoint
            self.m_lastPoint = curPos
            if not self.m_alreadySaveRange:
                self.saveAxisRange()
                self.m_alreadySaveRange = True
            self.charView.chart().scroll()

    def wheelEvent(self, event):
        curPos = event.pos()
        curVal = self.charView.chart().mapToValue(curPos)






